home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / src / op-str-str.cc < prev    next >
C/C++ Source or Header  |  1997-01-29  |  3KB  |  125 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. /* Modified by Klaus Gebhardt, 1997 */
  24.  
  25. #if defined (__GNUG__)
  26. #pragma implementation
  27. #endif
  28.  
  29. #ifdef HAVE_CONFIG_H
  30. #include <config.h>
  31. #endif
  32.  
  33. #include "gripes.h"
  34. #include "ov.h"
  35. #include "ov-str-mat.h"
  36. #include "ov-typeinfo.h"
  37. #include "ops.h"
  38.  
  39. // string by string ops.
  40.  
  41. static octave_value
  42. eq (const octave_value& a1, const octave_value& a2)
  43. {
  44.   CAST_BINOP_ARGS (const octave_char_matrix_str&,
  45.            const octave_char_matrix_str&);
  46.  
  47.   charMatrix cm1 = v1.char_matrix_value ();
  48.   charMatrix cm2 = v2.char_matrix_value ();
  49.  
  50.   if (cm1.rows () == 1 && cm1.columns () == 1)
  51.     {
  52.       if (cm2.rows () == 1 && cm2.columns () == 1)
  53.     return octave_value (cm1 (0, 0) == cm2 (0, 0));
  54.       else
  55.     SC_MX_BOOL_OP (char, c, cm1 (0, 0), \
  56.                charMatrix, m, cm2, \
  57.                c == m (i, j), 0.0);
  58.     }
  59.   else
  60.     {
  61.       if (cm2.rows () == 1 && cm2.columns () == 1)
  62.     MX_SC_BOOL_OP (charMatrix, m, cm1, \
  63.                char, c, cm2 (0, 0), \
  64.                c == m (i, j), 0.0);
  65.       else
  66.     MX_MX_BOOL_OP (charMatrix, m1, cm1, \
  67.                charMatrix, m2, cm2, \
  68.                m1 (i, j) == m2 (i, j), \
  69.                "==", 0.0, 1.0);
  70.     }
  71. }
  72.  
  73. static octave_value
  74. ne (const octave_value& a1, const octave_value& a2)
  75. {
  76.   CAST_BINOP_ARGS (const octave_char_matrix_str&,
  77.            const octave_char_matrix_str&);
  78.  
  79.   charMatrix cm1 = v1.char_matrix_value ();
  80.   charMatrix cm2 = v2.char_matrix_value ();
  81.  
  82.   if (cm1.rows () == 1 && cm1.columns () == 1)
  83.     {
  84.       if (cm2.rows () == 1 && cm2.columns () == 1)
  85.     return octave_value (cm1 (0, 0) != cm2 (0, 0));
  86.       else
  87.     SC_MX_BOOL_OP (char, c, cm1 (0, 0), charMatrix, m, cm2,
  88.                c != m (i, j), 1.0);
  89.     }
  90.   else
  91.     {
  92.       if (cm2.rows () == 1 && cm2.columns () == 1)
  93.     MX_SC_BOOL_OP (charMatrix, m, cm1, char, c, cm2 (0, 0),
  94.                c != m (i, j), 1.0);
  95.       else
  96.     MX_MX_BOOL_OP (charMatrix, m1, cm1, charMatrix, m2, cm2,
  97.                m1 (i, j) != m2 (i, j), "!=", 1.0, 0.0);
  98.     }
  99. }
  100.  
  101. static octave_value
  102. assign (octave_value& a1, const octave_value_list& idx,
  103.     const octave_value& a2)
  104. {
  105.   CAST_BINOP_ARGS (octave_char_matrix_str&, const octave_char_matrix_str&);
  106.  
  107.   v1.assign (idx, v2.char_matrix_value ());
  108.   return octave_value ();
  109. }
  110.  
  111. void
  112. install_str_str_ops (void)
  113. {
  114.   INSTALL_BINOP (eq, octave_char_matrix_str, octave_char_matrix_str, eq);
  115.   INSTALL_BINOP (ne, octave_char_matrix_str, octave_char_matrix_str, ne);
  116.  
  117.   INSTALL_ASSIGNOP (octave_char_matrix_str, octave_char_matrix_str, assign);
  118. }
  119.  
  120. /*
  121. ;;; Local Variables: ***
  122. ;;; mode: C++ ***
  123. ;;; End: ***
  124. */
  125.